// Copyright (C) joyinter
// All rights reserved.
// 
// Author : Jiang Li
// Date   : 2004-7-15

#ifndef __JZIP_H_COMMON_BASE__
#define __JZIP_H_COMMON_BASE__

#pragma once
#include "string"
using namespace std;

typedef struct file_time
{
	CTime creationTime;
    CTime lastAccessTime;
    CTime lastWriteTime;
}FILE_TIME;

class zip_file
{
public:
    virtual ~zip_file() {}

    virtual bool read(void* buf, size_t len, size_t& readed) = 0;
    virtual bool write(const void* buf, size_t len) = 0;

    bool read(void* buf, size_t len);

    template<typename T>
    bool read(T& t)
    {
        return read(&t, sizeof(T));
    }
    template<typename T>
    bool write(const T& t)
    {
        return write(&t, sizeof(T));
    }
    bool read_str(string& str);
    bool write_str(const string& str);
};

class zip_pkg
{
protected:
    zip_file*        m_file;
	
public:
    zip_pkg(zip_file* f);
    virtual ~zip_pkg();
    bool AppendUnZipLength(DWORD len);
	bool GetUnZipLength(DWORD &len);
    bool append(const char* path, const char* relPath = NULL);
    virtual bool extract(const char* dir);
	bool  GetFTime(const char* path, FILE_TIME &ftime);
	bool  SetFTime(const char* path, FILE_TIME &ftime);
};

class bzip2_file : public zip_file
{
protected:
    void* m_data;
public:
    bzip2_file();
    virtual ~bzip2_file();

    bool open(const char* path, bool writable = false);
    void close();

    virtual bool read(void* buf, size_t len, size_t& readed);
    virtual bool write(const void* buf, size_t len);
};

#endif  // __JZIP_H_COMMON_BASE__